
#include "../GenericDictionary/Document.h"
#include "../GenericDictionary/DictionaryParser.h"
#include "../GenericDictionary/ParsedFileListParser.h"

#include "GenericGraphBuilder.h"

#include <string>
#include <iostream>

template <typename T>
void print_document(const Dictionary::Document<T> *doc);

int main()
{
	using namespace Dictionary;

	ParsedFileListParser parsed_file_list_parser("D:\\slava\\projects\\THESIS_RELATED\\Parsing for graphs\\Tests\\Html test\\parsed_file_list.xml");

	ParsedFileListParser::parsed_files_t *parsed_files = parsed_file_list_parser.parse();

	ParsedFileListParser::parsed_files_t::iterator iter = parsed_files->begin(), iter_end = parsed_files->end();

	DictionaryParser<> *parser = new DictionaryParser<>();

	Graphs::GenericGraphBuilder<> *graph_builder = new Graphs::GenericGraphBuilder<>();
	
	for (; iter != iter_end; ++iter)
	{
		std::string &xml = (*iter);
		std::cout << xml << std::endl;

		parser->set_xml_to_parse(xml);

	  Document<> *doc = parser->parse();

		graph_builder->set_document(doc);
		Graphs::GenericGraphBuilder<>::graph_t *graph = graph_builder->build_graph();

	  //::print_document(doc);

	  delete doc;
	}

	delete parsed_files;
	delete graph_builder;

	return 0;
}

template <typename T> 
void
print_document(const Dictionary::Document<T> *doc)
{
	using namespace Dictionary;

	std::cout << "document name " << doc->get_document_name() << std::endl;
	std::cout << "total term count " << doc->get_total_term_count() << std::endl;
	std::cout << "unique term count " << doc->get_unique_term_count() << std::endl;
	std::cout << "total sentence count " << doc->get_total_sentence_count() << std::endl;

	const Dictionary::Document<T>::id_to_node_t *node_array = doc->get_node_array();

	Document<T>::id_to_node_t::const_iterator node_i = node_array->begin(), node_end = node_array->end();
	for (; node_i != node_end ; ++node_i)
	{
		Node<T> *node = (*node_i).second;
		std::cout << "Node id = " << node->get_id() << std::endl;
		std::cout << "  node term " << node->get_term() << std::endl;
		std::cout << "  total term frequency " << node->get_total_term_frequency() << std::endl;
     
		const Node<T>::unique_sections_t * sections = node->get_sections();
		Node<T>::unique_sections_t::const_iterator sec_i = sections->begin(), sec_end = sections->end();

		//sections
		for (; sec_i != sec_end; ++sec_i)
		{
			Section<T> *section = (*sec_i).second;

			std::cout << "Section type = " << section->get_section_type() << std::endl;
			std::cout << "    term frequency " << section->get_term_frequency() << std::endl;

			const Section<T>::sentence_number_t *sentences = section->get_sentence_array();
			Section<T>::sentence_number_t::const_iterator sen_i = sentences->begin(), sen_end = sentences->end();

			for (; sen_i != sen_end; ++sen_i)
			{
				Section<T>::term_place_in_sentence_t::const_iterator place_i = (sen_i->second)->begin(), place_end = (sen_i->second)->end();
				for (;  place_i != place_end; ++place_i)
				{
					Sentence<T> *sen = place_i->second;

					std::cout << "Sentence " << std::endl;
					std::cout << "sentence number " << sen->get_sentence_number() << std::endl;
					std::cout << "in sentence place " <<  sen->get_in_sentence_place() << std::endl;
					std::cout << "connecting word " << sen->get_connecting_word() << std::endl;
					std::cout << "next id " << sen->get_next_id() << std::endl;
					std::cout << "\n";
				}
			}

			std::cout << "\n";
		}

		std::cout << "\n";
	}

}